package com.cz.zslu.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.cz.zslu.common.ReturnObject;
import com.cz.zslu.entity.CompanyAphorism;
import com.cz.zslu.entity.CompanyContact;
import com.cz.zslu.entity.HonorBook;
import com.cz.zslu.entity.OriginAuthorization;
import com.cz.zslu.interceptor.IgnoreAuth;
import com.cz.zslu.model.CompanyIntroduce;
import com.cz.zslu.rest.BaseController;
import com.cz.zslu.service.CompanyAphorismService;
import com.cz.zslu.service.CompanyContactService;
import com.cz.zslu.service.HonorBookService;
import com.cz.zslu.service.IOriginAuthorizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 公司格言 前端控制器
 * </p>
 *
 * @author Bruce
 * @since 2019-06-10
 */
@RestController
@RequestMapping("/sys/aphorism")
@Api(description = "公司格言管理")
public class CompanyAphorismController extends BaseController<CompanyAphorismService, CompanyAphorism> {

    @Autowired
    private CompanyAphorismService companyAphorismService;


    @ApiOperation("获取详情")
    @IgnoreAuth
    @RequestMapping(value = "/findByStoreId", method = RequestMethod.POST)
    public ReturnObject<CompanyAphorism> findInfoById(@ApiParam("店铺id") @RequestParam Long storeId) {

        return new ReturnObject<>(0, "获取成功", companyAphorismService.selectOne(new EntityWrapper<CompanyAphorism>().eq("store_id", storeId)));
    }

    @ApiOperation("新增/编辑(新增时：id为空)")
    @RequestMapping(value = "/saveAphorism", method = RequestMethod.POST)
    public ReturnObject<CompanyAphorism> saveAphorism(@ApiParam("格言内容") @RequestParam String aphorismContent,
                                                      @ApiParam("商铺id") @RequestParam Long storeId,
                                                      @ApiParam("id") @RequestParam(defaultValue = "0") Long id) {
        if (id != 0) {
            CompanyAphorism info = baseService.selectById(id);
            info.setAphorismContent(aphorismContent);
            baseService.updateById(info);
        } else {
            CompanyAphorism info = new CompanyAphorism();
            info.setAphorismContent(aphorismContent);
            info.setStoreId(storeId);
            baseService.insert(info);
        }

        return new ReturnObject<>(0, "新增成功", null);
    }

    @ApiOperation("删除")
    @RequestMapping(value = "/delById", method = RequestMethod.POST)
    public ReturnObject<CompanyContact> delById(@ApiParam("id") @RequestParam Long id) {

        CompanyAphorism info = baseService.selectById(id);
        info.setState(1);
        baseService.updateById(info);

        return new ReturnObject<>(0, "删除成功", null);
    }

}

